import type { IApi } from 'umi';

export default (api: IApi) => {
  api.describe({
    key: 'pluginA',
    config: {
      schema(joi) {
        return joi.object({
          a: joi.string().required(),
          b: joi.string()
        });
        // return joi.string();
      },
    },
    enableBy: api.EnableBy.config
  });

  api.modifyConfig((memo, { paths }) => {
    debugger
    memo.favicons = api.userConfig.changeFavicon;

    memo.alias = {
      ...memo.alias,
      '@': paths.absSrcPath,
      "@utils": paths.absSrcPath + '/utils',
      "@temp:utils": paths.absSrcPath + '/.temp/utils', // 一些插件，动态注入别名，并注入temp.d.ts，确保eslint不会报错
    }
    return memo;
  });


  api.chainWebpack((memo, { webpack, env }) => {
    debugger
    // set alias
    memo.resolve.alias.set('a', 'path/to/a');
    // Delete progess bar plugin
    memo.plugins.delete('progess');
  })


  // 运行build的时候才会调用到这里
  api.modifyHTML(($, { path }) => {
    debugger
    $('head').prepend('<script>window.g={t:Date.now()}</script>');
    return $;
  })
};
